package org.kev.transit;
import org.kev.transit.util.TransitConst;

import com.google.android.maps.MapView;
import com.google.android.maps.MapController;
import com.google.android.maps.MapActivity;
import com.google.android.maps.Point;
import android.app.AlertDialog;
import android.os.Bundle;
import android.util.Log;
import android.view.KeyEvent;
import android.view.Menu;

/**
 * Map Test class.  Will be removed at some point
 * @author kevin
 *
 */
public class GmapTest extends MapActivity{
	   static final private int BACK_ID = Menu.FIRST;
	    static final private int MAP_ID = Menu.FIRST + 1;
	    static final private int NEXT_ID = Menu.FIRST + 2;
	    
	private MapView mapView=null;
	private MapController mControl=null;
	/**
	 *  Called when fist started
	 *  @param icicle
	 */
		@Override
		public void onCreate(Bundle icicle) {
			super.onCreate(icicle);
			try {
				// AlertDialog.show(this,"messge", "start", "Ok", false);
				// Inflate our UI from its XML layout description.
				//mapView = new MapView(this);
				setContentView(R.layout.tmap);
				
				mapView= (MapView) findViewById(R.id.gMapView);
				mControl=mapView.getController();
				Double dlat = 32.837567 * 1E6;
				Double dlong = -96.776383* 1E6;
				Log.d(TransitConst.TAG,"dlat="+dlat);
				Log.d(TransitConst.TAG,"dlong="+dlong);

				//Double lat = location.getLatitude()*1E6;
				//Double lng = location.getLongitude()*1E6;
				Point point = new Point(dlat.intValue(), dlong.intValue());
				
				mControl.centerMapTo(point, false);
				//int ilat = (int) Math.round(dlat);
				//int ilong = (int) Math.round(dlong);
				Log.d(TransitConst.TAG,"ilat="+dlat.intValue() );
				Log.d(TransitConst.TAG,"ilong="+dlong.intValue() );
				//Point p= new Point(0,0);
				//Point p2= new Point(-96,0);
				
				//mControl.animateTo(p);
				//mControl.centerMapTo(point, true);
				
				mControl.zoomTo(10);
				

			} catch (Exception e) {
				Log.e(TransitConst.TAG,"UKNOWN Error in "+this,e);
				//AlertDialog.show(this,"StackTrace",1, e.getMessage(), "Ok", false);
			}
		}
	    /**
	     * Called when your activity's options menu needs to be created.
	     */
	    @Override
	    public boolean onCreateOptionsMenu(Menu menu) {
	        super.onCreateOptionsMenu(menu);

	        // We are going to create two menus. Note that we assign them
	        // unique integer IDs, labels from our string resources, and
	        // given them shortcuts.
	        menu.add(0, BACK_ID, R.string.back).
	            setShortcut('0', 'b');
	        menu.add(0, NEXT_ID, R.string.next).
	            setShortcut('1', 'n');
	        menu.add(0, MAP_ID, R.string.map).
            setShortcut('2','m');
	        return true;
	    }

	    /**
	     * Called right before your activity's option menu is displayed.
	     */
	    @Override
	    public boolean onPrepareOptionsMenu(Menu menu) {
	        super.onPrepareOptionsMenu(menu);

	        // Before showing the menu, we need to decide whether the clear
	        // item is enabled depending on whether there is text to clear.
	       // menu.setItemShown(CLEAR_ID, mEditor.getText().length() > 0);

	        return true;
	    }

	    /**
	     * Called when a menu item is selected.
	     */
	    @Override
	    public boolean onOptionsItemSelected(Menu.Item item) {
	        switch (item.getId()) {
	        case BACK_ID:
	            finish();
	            return true;
	        case NEXT_ID:
	        	
	          //  mEditor.setText("");
	            return true;
	        case MAP_ID:
	        	//display where I am now plus transit stop 
	            return true;
	        }

	        return super.onOptionsItemSelected(item);
	    }
}
